﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms.DataVisualization.Charting;
using System.Drawing;

namespace ChartControl
{
    public class ChartEx : Chart
    {
        Queue<Color> border = new Queue<Color>();
        Queue<Color> colors = new Queue<Color>();
        Legend legend = new Legend();
        public bool LegendVisible { get; set; }

        public ChartEx()
        {
            border.Enqueue(System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105))))));
            colors.Enqueue(System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240))))));

            border.Enqueue(System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))));
            colors.Enqueue(System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(252)))), ((int)(((byte)(180)))), ((int)(((byte)(65))))));

            border.Enqueue(System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))));
            colors.Enqueue(System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(224)))), ((int)(((byte)(64)))), ((int)(((byte)(10))))));
        }
        public enum ChartTypes : byte
        {
            Style1 = 0,
            Style2 = 1,
            Style3 = 2,
            Style4 = 3
        }
        public ChartTypes ChartType { get; set; }
        public void AddArea(string area)
        {
            this.ChartAreas.Add(area);
        }
        public void AddSeries(string name, string chartArea, string xmember, ChartValueType xtype, string ymember, ChartValueType ytype)
        {
            Series series = new Series(name);
            series.ChartArea = chartArea;
            series.XValueType = xtype;
            series.XValueMember = xmember;
            series.YValueMembers = ymember;
            series.YValueType = ytype;
            this.Series.Add(series);
        }
        public void AddSeries(string name, string chartArea, string xmember, ChartValueType xtype, string ymember, ChartValueType ytype, SeriesChartType type)
        {
            Series series = new Series(name);
            series.ChartArea = chartArea;
            series.XValueType = xtype;
            series.XValueMember = xmember;
            series.YValueMembers = ymember;
            series.YValueType = ytype;
            series.ChartType = type;
            this.Series.Add(series);
        }


        public void InitChart()
        {
            border.Enqueue(System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105))))));
            colors.Enqueue(System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240))))));

            border.Enqueue(System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))));
            colors.Enqueue(System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(252)))), ((int)(((byte)(180)))), ((int)(((byte)(65))))));

            border.Enqueue(System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))));
            colors.Enqueue(System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(224)))), ((int)(((byte)(64)))), ((int)(((byte)(10))))));

            switch (ChartType)
            {
                case ChartTypes.Style1:
                    initStyle1();
                    break;
                case ChartTypes.Style2:
                    initStyle2();
                    break;
                case ChartTypes.Style3:
                    initStyle3();
                    break;
                case ChartTypes.Style4:
                    initStyle4();
                    break;
                default:
                    break;
            }

            if (this.LegendVisible)
            {
                legend.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
                legend.Name = "Legend";
                legend.BackColor = Color.Transparent;
                if (this.Legends.Contains(legend) == false)
                    this.Legends.Add(legend);
            }
        }
        void initStyle1()
        {
            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(243)))), ((int)(((byte)(223)))), ((int)(((byte)(193)))));
            this.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            this.BorderlineColor = System.Drawing.Color.FromArgb(((int)(((byte)(181)))), ((int)(((byte)(64)))), ((int)(((byte)(1)))));
            this.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.BorderlineWidth = 2;
            this.BorderSkin.SkinStyle = System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss;
            this.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Pastel;

            foreach (ChartArea area in this.ChartAreas)
            {
                area.Area3DStyle.Enable3D = true;
                area.Area3DStyle.Inclination = 15;
                area.Area3DStyle.IsClustered = true;
                area.Area3DStyle.IsRightAngleAxes = false;
                area.Area3DStyle.Perspective = 10;
                area.Area3DStyle.PointGapDepth = 0;
                area.Area3DStyle.Rotation = 5;
                area.Area3DStyle.WallWidth = 0;
                area.AxisX.Interval = 1;
                area.AxisX.IsLabelAutoFit = false;
                area.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F);
                area.AxisX.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.AxisY.IsLabelAutoFit = false;
                area.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
                area.AxisY.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.BackColor = Color.OldLace;
                area.BackSecondaryColor = System.Drawing.Color.White;
                area.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.Position.Auto = false;
                area.Position.Height = 75F;
                area.Position.Width = 100F;
                area.Position.Y = 8F;
                area.ShadowColor = System.Drawing.Color.Transparent;
            }

            foreach (Series series in this.Series)
            {
                series.BorderColor = border.Dequeue();
                series.Color = colors.Dequeue();
                series.CustomProperties = "DrawingStyle=Cylinder";
                series.ShadowColor = System.Drawing.Color.Transparent;
            }

            this.ResumeLayout();
        }
        void initStyle2()
        {
            this.BackColor = System.Drawing.Color.WhiteSmoke;
            this.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            this.BackSecondaryColor = System.Drawing.Color.White;
            this.BorderlineColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
            this.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.BorderlineWidth = 2;
            this.BorderSkin.SkinStyle = System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss;

            foreach (ChartArea area in this.ChartAreas)
            {
                area.Area3DStyle.Inclination = 15;
                area.Area3DStyle.IsClustered = true;
                area.Area3DStyle.IsRightAngleAxes = false;
                area.Area3DStyle.Perspective = 10;
                area.Area3DStyle.PointGapDepth = 0;
                area.Area3DStyle.Rotation = 5;
                area.Area3DStyle.WallWidth = 0;
                area.AxisX.Interval = 1;
                area.AxisX.IsLabelAutoFit = false;
                area.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
                area.AxisX.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.AxisY.IsLabelAutoFit = false;
                area.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
                area.AxisY.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.BackColor = System.Drawing.Color.Transparent;
                area.BackSecondaryColor = System.Drawing.Color.White;
                area.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.Position.Auto = false;
                area.Position.Height = 75F;
                area.Position.Width = 90F;
                area.Position.X = 2F;
                area.Position.Y = 13F;
                area.ShadowColor = System.Drawing.Color.Transparent;
            }

            foreach (Series series in this.Series)
            {
                series.BorderColor = border.Dequeue();
                series.Color = colors.Dequeue();
                series.CustomProperties = "DrawingStyle=Cylinder";
                series.ShadowColor = System.Drawing.Color.Transparent;
            }
        }
        void initStyle3()
        {
            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(243)))), ((int)(((byte)(223)))), ((int)(((byte)(193)))));
            this.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            this.BorderlineColor = System.Drawing.Color.FromArgb(((int)(((byte)(181)))), ((int)(((byte)(64)))), ((int)(((byte)(1)))));
            this.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.BorderlineWidth = 2;
            this.BorderSkin.SkinStyle = System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss;

            foreach (ChartArea area in this.ChartAreas)
            {
                area.Area3DStyle.Enable3D = true;
                area.Area3DStyle.Inclination = 18;
                area.Area3DStyle.IsClustered = true;
                area.Area3DStyle.IsRightAngleAxes = false;
                area.Area3DStyle.Perspective = 8;
                area.Area3DStyle.Rotation = 40;
                area.Area3DStyle.WallWidth = 0;
                area.AxisX.Interval = 1;
                area.AxisX.IsLabelAutoFit = false;
                area.AxisX.LabelAutoFitStyle = ((System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles)((((System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.DecreaseFont | System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.StaggeredLabels)
                            | System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.LabelsAngleStep30)
                            | System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.WordWrap)));
                area.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
                area.AxisX.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.AxisY.LabelAutoFitStyle = ((System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles)((((System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.DecreaseFont | System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.StaggeredLabels)
                            | System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.LabelsAngleStep30)
                            | System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.WordWrap)));
                area.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
                area.AxisY.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.BackColor = System.Drawing.Color.OldLace;
                area.BackSecondaryColor = System.Drawing.Color.White;
                area.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                area.ShadowColor = System.Drawing.Color.Transparent;
            }


            foreach (Series series in this.Series)
            {
                series.BorderColor = border.Dequeue();
                series.Color = colors.Dequeue();
                series.ShadowColor = System.Drawing.Color.Transparent;
            }
        }
        void initStyle4()
        {
            this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(211)), ((System.Byte)(223)), ((System.Byte)(240)));
            this.BackSecondaryColor = System.Drawing.Color.White;
            this.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            this.BorderlineColor = System.Drawing.Color.FromArgb(((System.Byte)(26)), ((System.Byte)(59)), ((System.Byte)(105)));
            this.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.BorderlineWidth = 2;
            this.BorderSkin.SkinStyle = System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss;

            foreach (ChartArea area in this.ChartAreas)
            {
                area.Area3DStyle.IsClustered = true;
                area.Area3DStyle.Perspective = 10;
                area.Area3DStyle.IsRightAngleAxes = false;
                area.Area3DStyle.WallWidth = 0;
                area.Area3DStyle.Inclination = 15;
                area.Area3DStyle.Rotation = 10;
                area.AxisX.LabelAutoFitMaxFontSize = 8;
                area.AxisX.LabelAutoFitMinFontSize = 8;
                area.AxisX.LabelAutoFitStyle = System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.None;
                area.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 6.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                area.AxisX.LabelStyle.Format = "MMM dd";
                area.AxisX.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
                area.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
                area.AxisY.LabelAutoFitMaxFontSize = 8;
                area.AxisY.LabelAutoFitMinFontSize = 8;
                area.AxisY.LabelAutoFitStyle = ((System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.IncreaseFont | System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.DecreaseFont)
                    | System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.WordWrap);
                area.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
                area.AxisY.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
                area.AxisY.LineWidth = 2;
                area.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
                area.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(165)), ((System.Byte)(191)), ((System.Byte)(228)));
                area.BackSecondaryColor = System.Drawing.Color.White;
                area.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
                area.BorderColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
                area.ShadowColor = System.Drawing.Color.Transparent;
            }
            foreach (Series series in this.Series)
            {
                series.BorderColor = border.Dequeue();
                series.Color = colors.Dequeue();
                series.CustomProperties = "DrawingStyle=LightToDark";
                series.ShadowColor = System.Drawing.Color.Transparent;
            }
        }
    }
}